<style>

</style>
<template>
    <section class="clearfix content">
        <aside class="fl nav-aside">
            <ul>
                <li v-for="item in searchList">
                    <span v-if="item.type == 'search'">{{item.name}}<input type="text" @keyup="keydownEnter" placeholder="{{item.place}}" v-model="param[item.code]"></span>
                    <span v-if="item.type == 'detail'" @click="toggleAside">{{item.name}}<i class="fr iconfont icon-right-1-copy"></i></span>
                </li>
            </ul>
            <div class="asidedetail">
                <h5 @click="toggleAside"><i class="iconfont icon-zuozuo-copy"></i>返回</h5>
            </div>
        </aside>
        <aside class="fr table-aside">
            <h5><span class="btn" @click="delete">删除</span> <span class="fr"><a href="#/applicationDetail">新增</a></span></h5>
            <div class="table-box">
                <table class="table table-bordered table-hover">
                    <thead>
                    <tr>
                        <td class="td-btn">操作</td>
                        <td v-for="it in lists | orderBy 'order'" v-if="it.status">{{it.name}}</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="maxLimit" v-for="(ind,item) in list">
                        <td class="td-btn"><input type="checkbox" value="{{item.id}}"></td>
                        <td v-for="it in lists | orderBy 'order'" @click="toDetail(item.id)" v-if="it.status">
                            <span v-if="it.type=='text'" v-bind:class="{'ell':it.code=='summary'}">{{item[it.code]}}</span>
                            <span v-if="it.type=='btn'&&it.code=='enabled'">{{item[it.code]?'启用':'关闭'}}</span>
                            <span v-if="it.type=='btn'&&it.code=='type'">{{item[it.code]}}</span>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </div>
            <page :page-no.sync="pageNo" :total-Page.sync="totalPage" :pages.sync="pages"
                  :page-size.sync="pageSize" :list.sync="list" :param.sync="param" :paths.sync="paths"></page>

        </aside>
    </section>
</template>
<script>
    module.exports = {
        data: function() {
            return {
                list:[],
                pageNo:1,
                pageSize:VIE.pageSize,
                totalPage:'',
                pages:[],
                lists:JSONLIST['application'],
                param:{},
                searchList:[
                    {name:'关键词',place:'',type:'search',code:'keyword'}
                ],
                cacheCheck:[],
                cacheBtn:false,
                type:[],
                paths:"api/application"
            }
        },
        methods: {
            render: function(){
                var params = {pageNumber:(this.pageNo - 1),pageSize:VIE.pageSize,keyword:this.param.keyword};
                VIE.getJ(HTTP_SERVER+'api/application',params,this,this.success,this.error);
            },
            success: function(data) {
                var _this = this;
                _this.list = data.content;
                _this.pageNo = data.number + 1;
                _this.pageSize = data.size;
                _this.totalPage = data.totalPages;
                _this.pages = [];
                for(var i = 1; i <= _this.totalPage; i++ ){
                    _this.pages[i-1] = i;
                }
            },
            error: function(xhr, type){
                if (xhr.status === 401) {
                    //  window.location = "login.html"
                }
            },
            toggleAside: function(){
                $(".nav-aside>ul,.nav-aside>.asidedetail").toggleClass('all');
            },
            renderList: function(){
                var _this = this;
                localStorage.setItem('application',JSON.stringify(_this.lists));
            },
            keydownEnter: function(e){
                if(e.keyCode == 13){
                    this.render();
                }
            },
            toDetail: function(id){
                router.go('applicationDetail?id='+id+"&type=1");
            },
            delete: function(){
                var data = [];
                $(":checked").each(function(){
                    data.push($(this).val());
                });
                VIE.postJ(HTTP_SERVER+'api/application/deleteall',{ids:data},this,this.render,this.error);
            },
        },
        ready: function() {
            var _this = this;
            var loads = function(){
                var lists = JSON.parse(localStorage.getItem('application'));
                _this.lists = lists ? lists:JSONLIST['application'];
                _this.render();
            }
            var name = window.location.hash.split('?')[0].replace("#/","");
            if(!name){
                name = "user";
            }
            if(!router.fn[name]){
                loads();
                router.fn[name] = loads;
            }
        }
    };
</script>